﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Admin.Controls
{
    public partial class AddPoster : System.Web.UI.UserControl
    {
        public string filePathPoster;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAddPoster_Click(object sender, EventArgs e)
        {
            try
            {
                int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_Poster", "Poster_ID"));
                if (txtLink.Text != "")
                {
                    if (fulImagePoster.HasFile)
                    {
                        if (LIB.Validate.CheckFileType(fulImagePoster.FileName))
                        {
                           
                                int idnextposter = nextid + 1;
                                string linkimage = fulImagePoster.FileName;
                                LIB.Validate saveimage = new LIB.Validate();
                                saveimage.ThayDoiKichThuocAnh(Server.MapPath("/Images/Image-Poster/"), linkimage, 940, fulImagePoster.PostedFile.InputStream);
                                filePathPoster = "/Images/Image-Poster/" + fulImagePoster.FileName;
                                string value = "" + idnextposter + ",N'" + txtName.Text + "','Index','" + filePathPoster + "','" + txtLink.Text + "','','200.600','" + DateTime.Now.ToString() + "'";
                                List<string> values = new List<string>();
                                values.Add(value);
                                DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Poster", "insertemployee", values, false);
                                Response.Redirect("/Admin/Index.aspx?panel=5&sub=4");
                            

                        }
                        else
                        {
                            Response.Write("<script>alert('Chỉ có thể upload file(.jpg,.png,.jpeg)')</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('Vui lòng upload ảnh poster...')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng nhập link liên kết...')</script>");
                }
            }
            catch (Exception)
            {
                Response.Redirect("/error.htm");
            }
        }
    }
}